<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseWardTypes.class.php';

Class WardTypes {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjWardTypes = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWardTypes = new BaseWardTypes();
			$objWardTypes->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWardTypes->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objWardTypes->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objWardTypes->setWardCatagoryId( ( true == isset( $row["ward_catagory_id"] ) ) ? $row["ward_catagory_id"] : 'NULL' );
			$objWardTypes->setIsPublished( ( true == isset( $row["is_published"] ) ) ? $row["is_published"] : 'NULL' );
			array_push( $arrobjWardTypes, $objWardTypes );
		}
		return $arrobjWardTypes;
	}
	public function fetchAllWardTypes() {
		$result = $this->connection->RunQuery("SELECT * FROM WARD_TYPES");
		$arrobjWardTypes = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWardTypes = new BaseWardTypes();
			$objWardTypes->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWardTypes->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objWardTypes->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objWardTypes->setWardCatagoryId( ( true == isset( $row["ward_catagory_id"] ) ) ? $row["ward_catagory_id"] : 'NULL' );
			$objWardTypes->setIsPublished( ( true == isset( $row["is_published"] ) ) ? $row["is_published"] : 'NULL' );
			array_push( $arrobjWardTypes, $objWardTypes);
		}
		return $arrobjWardTypes;
	}
	public function fetchAllWardTypesByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM WARD_TYPES WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjWardTypes = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWardTypes->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWardTypes->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objWardTypes->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objWardTypes->setWardCatagoryId( ( true == isset( $row["ward_catagory_id"] ) ) ? $row["ward_catagory_id"] : 'NULL' );
			$objWardTypes->setIsPublished( ( true == isset( $row["is_published"] ) ) ? $row["is_published"] : 'NULL' );
			array_push( $arrobjWardTypes, $objWardTypes );
		}
		return $arrobjWardTypes;
	}

	public function fetchWardTypesById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM WARD_TYPES WHERE id = " . $intId );
			$objWardTypes = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objWardTypes = new BaseWardTypes();
			$objWardTypes->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objWardTypes->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objWardTypes->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objWardTypes->setWardCatagoryId( ( true == isset( $row["ward_catagory_id"] ) ) ? $row["ward_catagory_id"] : 'NULL' );
			$objWardTypes->setIsPublished( ( true == isset( $row["is_published"] ) ) ? $row["is_published"] : 'NULL' );
		}
		return $objWardTypes;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from ward_types order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endWardTypes(){
		$this->connection->CloseMysql();
	}

}